package com.aiton.bamin.bamindaijiadrier.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.aiton.bamin.bamindaijiadrier.R;
import com.aiton.bamin.bamindaijiadrier.model.PayLog;

import java.text.SimpleDateFormat;
import java.util.List;


/**
 * 支付记录
 */
public class MyPayAdapter extends BaseAdapter {
    private final LayoutInflater inflater;
    private List<PayLog.ContainsEntity> containsPayLog;

    public MyPayAdapter(Context context, List<PayLog.ContainsEntity> containsPayLog) {
        inflater = LayoutInflater.from(context);

        this.containsPayLog = containsPayLog;
    }

    class ViewHolder {
        TextView textView_payType;
        TextView textView_time;
        TextView textView_payValue;
        TextView textView_forOther;
    }

    @Override
    public int getCount() {
        return containsPayLog.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = inflater.inflate(R.layout.pay_log_item, null);
            holder.textView_payType = (TextView) convertView.findViewById(R.id.textView_payType);
            holder.textView_time = (TextView) convertView.findViewById(R.id.textView_time);
            holder.textView_payValue = (TextView) convertView.findViewById(R.id.textView_payValue);
            holder.textView_forOther = (TextView) convertView.findViewById(R.id.textView_forOther);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        PayLog.ContainsEntity containsEntityPayLog = containsPayLog.get(position);
        String payType = "";
        if (containsEntityPayLog.getFlag() == 1) {
            payType = "代驾";
        } else {
            payType = "代驾";
        }
        if (!TextUtils.equals(containsEntityPayLog.getAccountBillPhone(),
                containsEntityPayLog.getConAccountPhone())) {
            holder.textView_forOther.setVisibility(View.VISIBLE);
            holder.textView_forOther.setText(containsEntityPayLog.getConAccountPhone());
        }
        holder.textView_payType.setText(payType);
        holder.textView_time.setText(sdf.format(containsEntityPayLog.getDate()));
        holder.textView_payValue.setText(containsEntityPayLog.getPrice() + "元");
        return convertView;
    }
}